package com.itheima.web.service.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.service.sms.BrandService;
import com.itheima.vo.sms.Brand;
import com.itheima.web.mapper.sms.BrandMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Override
    public Page<Brand> getpage(Integer pageNum, Integer pageSize, String brandName, Integer recommendStatus) {
        Page<Brand> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Brand> blqw=new LambdaQueryWrapper<>();
        blqw.like(Strings.isNotEmpty(brandName),Brand::getBrandName,brandName);
        blqw.eq(recommendStatus!=null,Brand::getRecommendStatus,recommendStatus);
        this.page(page,blqw);
        return page;
    }

    @Override
    public void updateByStatus(List<Integer> ids, Integer recommendStatus) {
/*        LambdaQueryWrapper<Brand> blqw=new LambdaQueryWrapper<>();
        blqw.in(Brand::getId,ids);
        Brand brand=new Brand();
        this.update(brand,blqw);*/

        List<Brand> brands = this.listByIds(ids);
        for (Brand brand : brands) {
            brand.setRecommendStatus(recommendStatus);
        }

        this.updateBatchById(brands);
    }
}
